/***************************************************************************
 *   Copyright (C) 2009 by pawel   *
 *   pawel@byszewski.pl   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
*
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "recorddescryptor.h"
#include <iostream>

using namespace std;


RecordDescriptor::RecordDescriptor()
{
}


RecordDescriptor::~RecordDescriptor()
{
}

void RecordDescriptor::setSize(int s)
{
	size=s;
}

void RecordDescriptor::setBooked(char c)
{	booked=c;
}

void RecordDescriptor::setOfset(int i)
{	ofset=i;
}

char RecordDescriptor::getBooked()
{	return booked;
}

int RecordDescriptor::getSize()
{	return size;
}

int RecordDescriptor::getOfset()
{	return ofset;
}
/*
void RecordDescryptor::toStream(fstream &f){
	f << booked;
	f << size;
	f << ofset;
}*/
void RecordDescriptor::setType(unsigned int i, char _type){
			type[i]=_type;
		}
char* RecordDescriptor::createBuf(){
			char *buf=new char[DESLENGTH];
			buf[0]=booked;
			char *temp;
			temp=(char *)&size;

			cout <<"dupa1 1"<<endl;
			for(int i=0;i<4;++i){
				cout <<"dupa1 1 "<<temp[i]<<endl;//size
				buf[i+1]=temp[i];
			}
			cout <<"dupa1 2"<<endl;
			temp=(char *)&ofset;
			for(int i=0;i<4;++i)//ofset
				buf[5+i]=temp[i];
			cout <<"dupa1 3"<<endl;
			for(int i=0;i<ELEMENTCOUNT;++i)
				buf[9+i]=type[i];
			return buf;
			
		}
		
void RecordDescriptor::wypisz(){
			cout <<endl <<"****START***"<<endl;
			int k=(int)booked;
			cout <<"zaj: "<<k<<"  size: "<<size<<"  ofset: "<<ofset <<"   typ: ";
			for(int i =0; i<ELEMENTCOUNT;++i){
				int k=(int)type[i];
				cout <<k;
			}
			cout <<endl<<"*********END******"<<endl;
		}
		
void RecordDescriptor::createFromBuf(char *buf){
			booked=buf[0];
			int *_size=(int*)(buf+1);
			size=*_size;
			int *_ofset=(int*)(buf+5);//bo tu sie zaczna ofset
			ofset=*_ofset;
			for(int i=0;i<ELEMENTCOUNT;++i)
				type[i]=buf[9+i];
		 
		}

